/**
 *
 *  @auth xlx_good@qq.com
 *  @date 17/6/21.
 *
 */

requirejs.config({
    baseUrl: '../../',
    paths:  {
        avalon: 'javascript/avalon.min',
        jquery: 'js/plugins/jquery/jquery-2.1.1.min',
        pagination: 'lib/pagination/jquery.pagination',
        WdatePicker: 'js/plugins/DatePicker/WdatePicker',
        config: 'javascript/config',
        api: 'javascript/api',
        layer: 'js/plugins/layer1/layer',
        arg: 'javascript/arg'
    },
    shim: {
        pagination: {
            deps: ['jquery']
        },
        api: {
            deps: ['jquery']
        },
        layer: {
            deps: ['jquery']
        }
    }
});


(function(win, dom, requirejs, initVm){
    var vm;
    requirejs(['avalon', 'jquery', 'pagination', 'WdatePicker', 'config', 'api', 'layer', 'arg'], function(){
        //初始化vm
        vm = initVm(dom);
    });

})(window, document, requirejs, function(dom){
    var vm = avalon.define({
        $id: 'container',
        form: {
            startTime: '',
            endTime: ''
        },
		params: {},
		list: [],
        search: function(){
			Api.reportWaresalePage(vm.form, function(resp) {
				if(resp.code == 0) {
					vm.list = resp.data;
					setPagination(vm.list.length, 1);
				} else {
					layer.msg(resp.msg);
				}
			});
        }
    })
	vm.params = Arg.parse(location.href);
    avalon.scan(dom.body);
	if(vm.params.date) {
		vm.form.startTime = vm.params.date;
		vm.form.endTime = vm.params.date;
		vm.search();
	}
    return vm;
});

/**
 * 设置翻页
 * @param <number> 总条数
 * @param <number> 当前页码
 * */
function setPagination(total, current){
    $('.pagination').pagination(total,{
        items_per_page: 10, //  每页显示条数
        current_page: current,
        num_display_entries: 20, // 显示的页面个数
        next_text: '下一页',
        prev_text: '上一页',
        num_edge_entries: 2, //省略号后面显示的页码个数
        callback: function(index){
			
        }
    });
}
